package com.atguigu.yygh.hosp.controller.user;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "医院显示接口")
@RestController
@RequestMapping("/user/hosp/hospital")
public class UserHospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation("获取医院信息")
    @GetMapping("/list")
    public R getHosptailPage(HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitalPage = hospitalService.getHospitalPage(1, 10000000, hospitalQueryVo);
        return R.ok().data("list",hospitalPage.getContent());
    }

    @ApiOperation("根据医院的名字进行模糊查询")
    @GetMapping("/{hosName}")
    public R getHosptailByHosname(@PathVariable String hosName){
       List<Hospital> list =  hospitalService.findByName(hosName);
       return R.ok().data("list",list);
    }


     @ApiOperation("根据医院的编号进行查询")
     @GetMapping("/detail/{hoscode}")
    public R getHosptialDetail(@PathVariable String hoscode){
       Hospital hospital = hospitalService.getHospitalDetail(hoscode);
        return  R.ok().data("hospital",hospital);
    }


}
